#include <stddef.h>
#include <sys/time.h>
#include "app_common.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

long long app_common_getTimeStamp(void){
    struct timeval tv;
    // 获取当前时间，包含秒和微秒
    gettimeofday(&tv, NULL);

    return tv.tv_sec*1000+tv.tv_usec/1000;
}
/*abcd->61626364*/
char* app_common_charsToHex(char* chars,int len){
    char* hex_buffer=(char*)malloc(len*2+1);
    for(int i=0;i<len*2;i++){
        sprintf(hex_buffer+i*2,"%02X",*(chars+i));
    }
    hex_buffer[len*2]='\0';
    return hex_buffer;
}

/*61626364->abcd*/
char* app_common_hexToChars(char* hex,int *chars_len){
    int hex_len=strlen(hex);
    *chars_len=hex_len/2;
    char* chars_buffer=(char*)malloc(hex_len/2);
    for(int i=0;i<hex_len;i+=2){
        sscanf(hex+i,"%02X",(unsigned int*)(chars_buffer+i/2));
    }
    return chars_buffer;
}